package com.hubei.tools;

import java.sql.Connection;
import java.sql.DriverManager;

public class JDBCTool {

    private static Connection conn = null;

    public static Connection getConnection() throws Exception {
        if (conn == null || conn.isClosed()) {
            String username = "root";
            String password = "123456";
            String url = "jdbc:mysql://localhost:3306/test?characterEncoding=UTF-8&useSSL=false&useUnicode=true&serverTimezone=Asia/Shanghai&allowPublicKeyRetrieval=true";

            // 手动注册 JDBC 驱动
            Class.forName("com.mysql.cj.jdbc.Driver");

            conn = DriverManager.getConnection(url, username, password);
        }
        return conn;
    }
}
